package com.example.mall.service.impl;

import com.example.mall.mapper.GoodsMapper;
import com.example.mall.pojo.Goods;
import com.example.mall.pojo.NewGoodsList;
import com.example.mall.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class GoodsServiceImpl implements GoodsService {

    GoodsMapper goodsMapper;


    @Override
    public List<Goods> selectAll(Integer pagenum,Integer pagesize) {
        PageHelper.startPage(pagenum,pagesize);
        List<Goods> goodsList = goodsMapper.getGoodsList();

        return goodsList;
    }

    @Override
    public PageInfo<Goods> getPagesAll(Integer pagenum) {
        List<Goods> goodsList = goodsMapper.getGoodsList();
        PageInfo<Goods> goodsPageInfo = new PageInfo<>(goodsList);
        return goodsPageInfo;
    }

    @Override
    public Boolean deleteById(Integer id) {
        int i = goodsMapper.deleteGoods(id);
        if(i==1){
            return  true;
        }else {
            return false;
        }
    }

    @Override
    public List<Goods> selectByName(String goodsName,Integer pagenum,Integer pagesize) {
        PageHelper.startPage(pagenum,pagesize);
        List<Goods> goodByName = goodsMapper.getGoodByName(goodsName);
        return goodByName;
    }

    @Override
    public PageInfo<Goods> getPagesByName(String goodsName, Integer pagenum) {
        List<Goods> goodByName = goodsMapper.getGoodByName(goodsName);
        PageInfo<Goods> goodsPageInfo = new PageInfo<>(goodByName);
        return goodsPageInfo;
    }

    @Override
    public Goods getGoodsName(String name) {
        Goods goodsName = goodsMapper.getGoodsName(name);
        if(goodsName==null){
            return null;
        }

        return goodsName;
    }

    @Override
    public Boolean addGoods(String goods_name, Integer goods_price, Integer goods_number, Short goods_weight, Integer cat_id, String goods_introduce, String goods_big_logo, String goods_small_logo, Integer add_time, Integer upd_time, Integer hot_mumber, Short is_promote, Integer goods_state) {
        int i = goodsMapper.addGoods(goods_name, goods_price, goods_number, goods_weight, cat_id, goods_introduce, goods_big_logo, goods_small_logo, goods_state, add_time, upd_time, hot_mumber, is_promote);
       if(i==1){
           return true;
       }
        return false;
    }


}
